//下列操作均为模块引入
var http = require("http");
var fs = require("fs");
var path = require("path");//利用path模块的join方法
http.createServer((req,res) => {
    // res.end("hello world");
    res.writeHead(200,{"Content-Type": "text/html"});//正常响应状态码为200
    /**
     * 向网页中插入图片
     */
    var filePath = path.join(__dirname, "../123abc.jpg");
    var imgBuf = fs.readFileSync(filePath);
    var imgBase64 = imgBuf.toString("base64");
    // console.log(imgBuf);
    res.write("<!DOCTYPE html><html>" + 
        "<head></head><body style='background: red'>" +
        // "<img src = '../123abc.jpg'>" + 
        "<img src = 'data:image/jpg; base64, "+
            imgBase64//只有小图标才会考虑转为base64
        +"' />" +
        "</body></html>"
    )
    res.end();
}).listen(8081);

console.log("server is lisening 8081");